 subroutine getpqrvo_ri(icore, iin, irrepiin, rivv,rivo, ioppq)
! One should note that the memory in getpqr is nabc*2 
! so the memory size of icore must be carefully treatted
 use mod_ri
 use mod_iop
 use mod_symm
 use mod_orbit
 implicit none 
!----------------------------------
 integer, intent(in) ::  iin, irrepiin,ioppq 
 real*4, intent(in) :: rivv(*), rivo(*)
 real*4, intent(out) :: icore(*)

 integer irrep, n, a, b, c, d
 integer numa, numb, numc, numd
 integer numab, numcd, ioff, nabc, ioffd,ioffd2(2000, 8), ioffout
 integer irrepa, irrepb, irrepc, irrepd, numnb, i0, i1
 integer irrepab, irrepcd, nsize, ioffabc, numna
 integer irrepi, numi, i, ioffi, ioffvo(8), ioffi2(2000, 8), irrepiin
 integer, external :: irpdso, idsymsoc, isymoffso
 real*8, external :: nrm2so

 zorb(1:8) = 0 
 zorb(1) = 1
 ioffvo(1) = 1
 do irrep = 1, nirrep - 1
    numna = irpdso(irrep, vrta, naux8, 1)
    numi = popa(irrep)
    ioffvo(irrep+1) = ioffvo(irrep) + numna*numi*isd
 enddo

! <ab|ci> = (ac|bi) 
 nsize = idsymsoc( 1, naux8, zorb, 1, vrta, vrta, 1)
! write(6,*)'norm of rivv', nsize, nrm2so(nsize, rivv, 1), nrm2so(nsize, rivv2,1)
 do irrepi = 1, nirrep
    numnb = irpdso(irrepi, naux8, vrta, 1)
    numi = popa(irrepi)
    do i = 1, numi
       ioffi = ioffvo(irrepi)-1 + (i-1)*numnb*isd + 1
       ioffi2(i,irrepi) = ioffi
    enddo 
  enddo

       nabc = idsymsoc(irrepiin, vrta, vrta, 1, vrta, zorb, 1)
       ioffi = ioffi2(iin, irrepiin)
       irrepi = irrepiin
       i0 = 1
       i1 = i0 + nabc*isd
       call VmnpqVmnrs_to_Vpqrs(rivv, rivo(ioffi), 1, irrepi, naux8, zorb, 1, vrta, vrta, 1, &
                     vrta, zorb, 1, icore(i1), irrepi, 1.d0, 0.d0)
       call sstgenso(icore(i1), icore,  nsize, vrta, vrta, vrta, zorb, icore,&
                     irrepi, '1324')
!<AB||CI> = <AB|CI> - <BA|CI>
       if(ioppq==0) then 
          call isymtrso(icore, icore(i1), vrta, vrta, 1, 1, vrta, zorb, 1, 0, irrepi)
          call axpyso(nabc, -1.d0, icore(i1), 1, icore, 1)
          call icompso(icore, icore(i1), vrta, vrta, 1, 0, vrta, zorb, 1, 1,irrepi) 
          nabc = idsymsoc(irrepi, vrta, vrta, 0, vrta, zorb, 1) 
          call myicopyso(icore(i1), icore, nabc)
       endif
  return
  end
